#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

const int N = 25, INF = 1e9 + 10;

int n, m;
int R[N], H[N];
int minV[N], minS[N];
int ans = INF;

void dfs(int k, int v, int s){
    

    if(v + minV[k] > n) 
        return;
    
    if(s + minS[k] >= ans) 
        return;
    
    if(s + 2 * (n - v) / R[k + 1] >= ans)
        return;

    if(!k){
        if(v == n){
            ans = s;
        }
        return;
    }

    for (int r = min(R[k + 1] - 1, (int)sqrt(n - v)); r >= k; r--){
        for (int h = min(H[k + 1] - 1, (n - v) / r / r); h >= k; h--){
            int t = 0;
            if(k == m)
                t = r * r;

            R[k] = r, H[k] = h;
            dfs(k - 1, v + r * r * h, s + t + 2 * r * h);
            R[k] = 0, H[k] = 0;
        }
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    cin >> n >> m;

    for (int i = 1; i <= m; i ++){
        minV[i] = minV[i - 1] + i * i * i;
        minS[i] = minS[i - 1] + 2 * i * i;
    }

    R[m + 1] = H[m + 1] = INF;
    dfs(m, 0, 0);
  

    cout << ans;

    return 0;
}